package cn.edu.neusoft.yuejian12.Activity;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import cn.edu.neusoft.yuejian12.JavaBean.TrainInfo;
import cn.edu.neusoft.yuejian12.Model.TrainModel;
import cn.edu.neusoft.yuejian12.R;
import cn.edu.neusoft.yuejian12.Service.TrainService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by 木子李 on 2017/10/10.
 */

public class TrainInfoActivity extends AppCompatActivity {
    private ImageView ic_back,trainThumb;
    private TextView trainName,trainInfo,trainNeed,trainTime,trainAdd,trainM;
    private String train_id;
    private Context mContext;
    private TrainInfo traininfo;
    private LinearLayout train_zixun,trainApply;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_train_info);
        initView();
        initEvents();
        initData();


    }
    public void initView(){
        ic_back=(ImageView) findViewById(R.id.ic_back);
        trainName=(TextView)findViewById(R.id.trainName);
        trainInfo=(TextView)findViewById(R.id.trainInfo);
        trainNeed=(TextView)findViewById(R.id.trainNeed);
        trainThumb=(ImageView)findViewById(R.id.trainThumb);
        trainAdd=(TextView) findViewById(R.id.trainAdd);

        trainTime=(TextView) findViewById(R.id.trainTime);
        trainM=(TextView) findViewById(R.id.trainM);
        train_zixun = (LinearLayout) findViewById(R.id.train_zixun);
        trainApply = (LinearLayout) findViewById(R.id.train_apply);





    }
    public void initEvents(){
        ic_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        trainApply.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(TrainInfoActivity.this,OrderActivity.class);
                intent.putExtra("train_id",train_id);
                intent.putExtra("price",traininfo.getPrice());
                intent.putExtra("name",traininfo.getName());
                intent.putExtra("bmnotice",traininfo.getBmnotice());
                startActivity(intent);

            }
        });
        train_zixun.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(TrainInfoActivity.this, "电话", Toast.LENGTH_SHORT).show();
                Intent phone = new Intent(Intent.ACTION_DIAL);
                Uri data = Uri.parse("tel:" + "13342278097");
                phone.setData(data);
                startActivity(phone);
            }
        });




    }
    public void initData(){
        Intent intent = getIntent();
        train_id = intent.getStringExtra("train_id");
        getTrainInfo();

    }
    public void getTrainInfo(){
        TrainModel trainModel = new TrainModel();
        Call<TrainInfo> call = trainModel.gettraininfo(train_id);
        call.enqueue(new Callback<TrainInfo>() {
            @Override
            public void onResponse(Call<TrainInfo> call, Response<TrainInfo> response) {
                traininfo = response.body();
                trainName.setText(traininfo.getName());
                trainInfo.setText(traininfo.getIntro());
                trainNeed.setText(traininfo.getNotice());
                trainTime.setText(traininfo.getTraintime());
                trainAdd.setText(traininfo.getPlace());
                trainM.setText("￥"+traininfo.getPrice());
                String address = "http://172.24.10.175/workout/Uploads/"+traininfo.getThumb();
                if(!traininfo.getThumb().equals("")){
                    Picasso.with(mContext).load(address).into(trainThumb);
                }
            }

            @Override
            public void onFailure(Call<TrainInfo> call, Throwable t) {

            }
        });
    }


}

